package skylineUB10;

import java.awt.*;

@SuppressWarnings("serial")
public class SkyPanel extends Panel {
	
	SkyFrame myFrame;
	
	
	int transformedX(Point p) {
		return (int)(p.x*SkyFrame.ZOOM_FACTOR)+SkyFrame.BORDER_SIZE;
	}	

	
	int transformedY(Point p) {
		return SkyFrame.FRAME_HEIGHT-(int)(p.y*SkyFrame.ZOOM_FACTOR)-SkyFrame.BORDER_SIZE;
	}
	
	
	SkyPanel(SkyFrame mF) {
		this.myFrame = mF;
	}
	
	
	void drawBuilding(Graphics g, Building b) {
		int oldX = 0, oldY = 0;
		boolean first;
		
		g.setColor(b.col);
		first = true;
		for (Point p : b.points) {
			if (first) {
				oldX = transformedX(p);
				oldY = SkyFrame.FRAME_HEIGHT-SkyFrame.BORDER_SIZE;
				first = false;
			}
			g.drawLine(oldX, oldY, transformedX(p), transformedY(p));
			oldX = transformedX(p);
			oldY = transformedY(p);
		}
		g.drawLine(oldX, oldY, oldX, SkyFrame.FRAME_HEIGHT-SkyFrame.BORDER_SIZE);
	}
	
	
	public void paint(Graphics g) {
		// draw background		
		g.setColor(Color.WHITE);
		g.fillRect(0,0,myFrame.getWidth(),myFrame.getHeight());
		
		// draw buildings
		for (Building b : DataContainer.buildings) drawBuilding(g, b);

		// draw sky line
		if (myFrame.container.drawSkyline) drawBuilding(g, myFrame.container.skyline);
	}

}
